package com.second.app.future;

/**
 * @Author GYZ
 * <pre>
 *
 * </pre>
 */
public class PriorityDemo {

    public static final int SLEEP_GAP = 1000;

    static class PrioritySetThread extends Thread {

        static int threadNo = 1;

        public long opportunities = 0;

        public PrioritySetThread() {
            super("thread--" + threadNo);
            threadNo++;
        }

        @Override
        public void run() {
            for (int i = 0; ; i++) {
                opportunities++;
            }
        }

        public static void main(String[] args) throws InterruptedException {
            PrioritySetThread[] threads = new PrioritySetThread[10];
            for (int i = 0; i < threads.length; i++) {
                threads[i] = new PrioritySetThread();
                threads[i].setPriority(i+1);
            }
            for (PrioritySetThread thread : threads) {
                thread.start();
            }
            Thread.sleep(SLEEP_GAP);
            for (PrioritySetThread thread : threads) {
                thread.stop();//停止
            }
            for (int i = 0; i < threads.length; i++) {
                System.out.println(threads[i].getName()+"--优先级为--"+threads[i].getPriority());
                System.out.println(threads[i].getName()+"--机会值为--"+threads[i].opportunities);
            }

        }
    }
}



